﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Bornander.UI.ListItems
{
    public partial class UserList : UserControl, IExtendedListItem
    {
        private bool onOddRow = false;
        private bool isSelected = false;
        public UserList()
        {
            InitializeComponent();
        }
        public UserList(Image _Header,string _UserName,string _Phone,string _uid,string _hasmsg)
        {
            InitializeComponent();
            this.Header.Image = _Header;
            this.UserName.Text = _UserName;
            this.Phone.Text = _Phone;
            this.uid = _uid;
            if(_hasmsg!=null)
            {
                this.isAlert.Text = _hasmsg + "条新信息";
            }
            else
            {
                this.isAlert.Text =  "非推信用户";
            }
            
            SetSelectedState(false);
        }

        private void SetSelectedState(bool isSelected)
        {
            SetBackColor();
        }
        private void SetBackColor()
        {
            if (isSelected)
                //BackColor = onOddRow ? Color.AliceBlue : Color.LightBlue;
                BackColor =  Color.LightBlue;
            else
                //BackColor = onOddRow ? Color.White : Color.Silver;
                BackColor = Color.White;
        }

        #region IExtendedListItem Members

        public void SelectedChanged(bool isSelected)
        {
            this.isSelected = isSelected;
            SetSelectedState(isSelected);
            SetBackColor();
        }

        public void PositionChanged(int index)
        {
            onOddRow = (index & 1) == 0;
            SetBackColor();
        }

        #endregion

        #region Public properties
 

        public string mUserName
        {
            get { return UserName.Text; }
        }

        public string mPhone
        {
            get { return Phone.Text; }
        }

        public string uid { get; set; }
        public string hasMsg { get; set; }
        #endregion

        private void isAlert_Click(object sender, EventArgs e)
        {
            MessageBox.Show(this.uid);
        }
    }
}
